package ModelLayer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * 
 * @author Kim Dam Gr�nh�j
 * @version 09-12-2014
 *
 */
public class Product implements Serializable
{	
	private static final long serialVersionUID = 3586234212950005765L;
	
	private int productNumber;
	private int amountInStock;
	private String name;
	private String description;
	private Double price;
	private String barcode;
	private int minStockAmount;
	private int maxStockAmount;
	private String expectedInStock;
	private ArrayList<Copy> copies;
	private Supplier supplier;
	private ArrayList<SupplierOrder> supplierOrders; 

	public Product(int productNumber, int amountInStock, String name, String description, Double price, String barcode, int minStockAmount, int maxStockAmount, String expectedInStock, Supplier supplier)
	{
		this.productNumber = productNumber;
		this.amountInStock = amountInStock;
		this.name = name;
		this.description = description;
		this.price = price;
		this.barcode = barcode;
		this.minStockAmount = minStockAmount;
		this.maxStockAmount = maxStockAmount;
		this.expectedInStock = expectedInStock;
		this.copies = new ArrayList<Copy>();
		this.supplier = supplier;
		this.supplierOrders = new ArrayList<SupplierOrder>();
	}
	/**
	 * gets all supplierOrders
	 */
	public ArrayList<SupplierOrder> getSupplierOrders()
	{
		return supplierOrders;
	}
	
	/**
	 * Methods there adds a supplierOrder to the ArrayList supplierorders
	 */
	public void addSupplierOrder(SupplierOrder supplierOrder)
	{
		supplierOrders.add(supplierOrder);
	}
	
	
	/**
	 * Gets item id of this product
	 * @return integer with item id
	 */
	public int getProductNumber()
	{
		return productNumber;
	}

	/**
	 * Sets productNumber of this product
	 * @param productNumber integer item id
	 */
	public void setProductNumber(int productNumber)
	{
		this.productNumber = productNumber;
	}

	/**
	 * Gets number of product items of this product
	 * @return integer with number of items
	 */
	public int getAmountInStock()
	{
		return amountInStock;
	}

	/**
	 * Sets number of product items
	 * @param amountInStock integer number of items
	 */
	public void setAmountInStock(int amountInStock)
	{
		this.amountInStock = amountInStock;
	}

	/**
	 * Gets fullname of this product
	 * @return String name of this product
	 */
	public String getName()
	{
		return name;
	}

	/**
	 * Sets fullname of this product
	 * @param name String name of this product
	 */
	public void setName(String name)
	{
		this.name = name;
	}

	/**
	 * Gets description of this product
	 * @return String description of this product
	 */
	public String getDescription()
	{
		return description;
	}

	/**
	 * Sets description of this product
	 * @param description String description of this prodyct
	 */
	public void setDescription(String description)
	{
		this.description = description;
	}

	/**
	 * Gets price of this product in DKK
	 * @return Double with price of this prodyct
	 */
	public Double getPrice()
	{
		return price;
	}

	/**
	 * Sets price of this product in DKK
	 * @param price Double price of this product
	 */
	public void setPrice(Double price)
	{
		this.price = price;
	}

	/**
	 * Gets barcode of this product
	 * @return String barcode
	 */
	public String getBarcode()
	{
		return barcode;
	}

	/**
	 * Sets barcode of this product
	 * @param barcode String barcode
	 */
	public void setBarcode(String barcode)
	{
		this.barcode = barcode;
	}

	/**
	 * Gets minimum stock amount of this product
	 * - Its a setting used to say the system have to order for new products if amoutInStock is under this value
	 * @return integer minimum stock amout
	 */
	public int getMinStockAmount()
	{
		return minStockAmount;
	}
	
	/**
	 * Sets minimum stock amount of this product
	 * - Its a setting used to say the system have to order for new products if amoutInStock is under this value
	 * @param minStockAmount integer minimum stock amout
	 */
	public void setMinStockAmount(int minStockAmount)
	{
		this.minStockAmount = minStockAmount;
	}

	/**
	 * Gets maximum stock amount of this product
	 * - Its a setting used to say the system cant order new product before inStockAmount is lower
	 * @return integer maximum stock amout
	 */
	public int getMaxStockAmount()
	{
		return maxStockAmount;
	}

	/**
	 * Sets maximum stock amount of this product
	 * - Its a setting used to say the system cant order new product before inStockAmount is lower
	 * @param macStockAmount integer maximum stock amout
	 */
	public void setMaxStockAmount(int maxStockAmount)
	{
		this.maxStockAmount = maxStockAmount;
	}
	
	/**
	 * Gets expectedInstock to see status if new products is on the way
	 * @return String expectedInstock status
	 */
	public String getExpectedInStock()
	{
		return expectedInStock;
	}
	
	/**
	 * Sets expectedInstock to see status if new products is on the way
	 * @param expectedInStock string status
	 */
	public void setExpectedInStock(String expectedInStock)
	{
		this.expectedInStock = expectedInStock;
	}
	
	/**
	 * Gets supplier they ordred products from
	 * @return Supplier object
	 */
	public Supplier getSupplier()
	{
		return this.supplier;
	}
	
	/**
	 * Sets supplier they ordre products from
	 * @param supplier object
	 */
	public void setSupplier(Supplier supplier)
	{
		this.supplier = supplier;
	}
	
	/**
	 * This method adds a copy to this product Copy list
	 * @param copy insert copy object
	 */
	public void addCopy(Copy copy)
	{
		this.copies.add(copy);
	}
	
	/**
	 * With this method you can find a copy by serialnumber
	 * - using search pattern
	 * @param serialNumber Insert string number
	 * @return Copy object
	 */
	public Copy searchCopy(String serialNumber)
	{
		Boolean found = false;	
		int i = 0;
		Copy foundCopy = null;
		
		while (!found && this.copies.size() > i)
		{
			Copy current = this.copies.get(i);
			
			if (current.getSerialNumber().equals(serialNumber))
			{
				found = true;
				foundCopy = current;
			} else {
				i++;
			}
		}
		
		return foundCopy;
	}
	
	/**
	 * With this method you can find a Copy and remove it
	 * - This method use search pattern
	 * @param serialNumber insert string number
	 */
	public void removeCopy(String serialNumber)
	{
		Boolean found = false;	
		
		Iterator<Copy> icopies = this.copies.iterator();
		while (!found && icopies.hasNext())
		{
			Copy current = icopies.next();
			
			if (current.getSerialNumber().equals(serialNumber))
			{
				found = true;
				icopies.remove();
			}
		}
	}
}
